package com.bafa.front;

import com.bafa.dbcache.LeagueCache;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bafa.exceptions.ErrorException;
import com.bafa.front.presentationbeans.FixturesListBean;
import com.bafa.front.presentationbeans.ResultsListBean;
import com.bafa.front.presentationbeans.SeasonBean;
import com.bafa.front.utils.FrontUtils;
import com.bafa.objects.Match;
import com.bafa.objects.PageBean;
import com.bafa.objects.season.Season;
import com.bafa.services.RetrieveServices;

public class DisplayDivisionFixturesServlet extends DaddyServlet {

	
	@Override
	public void doEvent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ErrorException {
		
		SeasonBean season = FrontUtils.getThisSeason(request);
	    request.setAttribute("FIXTURES",new FixturesListBean(RetrieveServices.getDivision(request.getParameter("seasonId"),request.getParameter("divisionId")).matchArray()));
	    String groupDiv="";
	    if(season.isLeague()){
	            groupDiv = "Division";
	    }else{
	            groupDiv = "Group";
	    }
	    PageBean pageBeanTemp = (PageBean)LeagueCache.getPages().get("fixtures");
	    pageBean = new PageBean(pageBeanTemp);
	    pageBean.setPageheader(pageBean.getPageheader().replaceAll("<>",season.getName()+" "+season.getYear()+" "+groupDiv+" "+request.getParameter("divisionId")));
	    pageBean.setMainheader(pageBean.getMainheader().replaceAll("<>",season.getName()+" "+season.getYear()+" "+groupDiv+" "+request.getParameter("divisionId")));
	}
}
